package com.itheima.demo01lambda;

import com.itheima.demo01lambda.Swimmable;

public class Demo01LambdaUse {
    public static void main(String[] args) {
        goSwimming(new Swimmable(){
            @Override
            public void swimming() {
                System.out.println("这是匿名内部类的游泳");
            }
        });

        // 小结：以后看到方法的参数是接口，就可以考虑Lambda表达式
        goSwimming(() -> {
            System.out.println("这是Lambda的游泳");
        });

        goSmoking(new Smokeable() {
            @Override
            public int smoking(String name) {
                System.out.println("匿名内部类 抽了" + name + "的香烟");
                return 12;
            }
        });

        goSmoking((String name) -> {
            System.out.println("Lambda 抽了" + name + "的香烟");
            return 6;
        });
    }

    // 练习无参数无返回值的Lambda
    public static void goSwimming(Swimmable swimmable){
        swimmable.swimming();
    }

    // 练习有参数有返回值的Lambda
    public static void goSmoking(Smokeable smokeable){
        int result = smokeable.smoking("中华");
        System.out.println("返回值是：" + result);
    }

}